<?php

/**
 * This is the model class for table "m_student_class".
 *
 * The followings are the available columns in table 'm_student_class':
 * @property string $id
 * @property integer $student_id
 * @property integer $kelas_tahun_ajaran_id
 * @property string $monthly_fee
 * @property string $disc_monthly_fee
 * @property string $notes
 * @property string $status
 * @property string $status_notes
 * @property integer $is_active
 * @property string $input_date
 * @property string $last_update_date
 * @property string $delete_date
 * @property integer $last_user_id
 *
 * The followings are the available model relations:
 * @property MStudent $student
 * @property MKaryawan $lastUser
 * @property MKelasTahunAjaran $kelasTahunAjaran
 * @property MStudentMonthlyFee[] $mStudentMonthlyFees
 */
class MStudentClass extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'm_student_class';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('student_id, kelas_tahun_ajaran_id, input_date, last_user_id', 'required'),
			array('student_id, kelas_tahun_ajaran_id, is_active, last_user_id', 'numerical', 'integerOnly'=>true),
			array('monthly_fee, disc_monthly_fee', 'length', 'max'=>14),
			array('status', 'length', 'max'=>20),
			array('notes, status_notes, last_update_date, delete_date', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, student_id, kelas_tahun_ajaran_id, monthly_fee, disc_monthly_fee, notes, status, status_notes, is_active, input_date, last_update_date, delete_date, last_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'student' => array(self::BELONGS_TO, 'MStudent', 'student_id'),
			'lastUser' => array(self::BELONGS_TO, 'MKaryawan', 'last_user_id'),
			'kelasTahunAjaran' => array(self::BELONGS_TO, 'MKelasTahunAjaran', 'kelas_tahun_ajaran_id'),
			'mStudentMonthlyFees' => array(self::HAS_MANY, 'MStudentMonthlyFee', 'student_class_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'student_id' => 'Student',
			'kelas_tahun_ajaran_id' => 'Kelas Tahun Ajaran',
			'monthly_fee' => 'Monthly Fee',
			'disc_monthly_fee' => 'Disc Monthly Fee',
			'notes' => 'Notes',
			'status' => 'Status',
			'status_notes' => 'Status Notes',
			'is_active' => 'Is Active',
			'input_date' => 'Input Date',
			'last_update_date' => 'Last Update Date',
			'delete_date' => 'Delete Date',
			'last_user_id' => 'Last User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('student_id',$this->student_id);
		$criteria->compare('kelas_tahun_ajaran_id',$this->kelas_tahun_ajaran_id);
		$criteria->compare('monthly_fee',$this->monthly_fee,true);
		$criteria->compare('disc_monthly_fee',$this->disc_monthly_fee,true);
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('status_notes',$this->status_notes,true);
		$criteria->compare('is_active',$this->is_active);
		$criteria->compare('input_date',$this->input_date,true);
		$criteria->compare('last_update_date',$this->last_update_date,true);
		$criteria->compare('delete_date',$this->delete_date,true);
		$criteria->compare('last_user_id',$this->last_user_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MStudentClass the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
